define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'video_chapter/index' + location.search,
                    add_url: 'video_chapter/add',
                    edit_url: 'video_chapter/edit',
                    del_url: 'video_chapter/del',
                    multi_url: 'video_chapter/multi',
                    import_url: 'video_chapter/import',
                    table: 'video_chapter',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'video_id', title: __('Video_id'), visible: false},
                        {field: 'channel_id', title: __('Channel_id'), visible: false},
                        {
                            field: 'video.title',
                            title: __('Video.title'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'channel.type', title: __('Channel.type'), searchList: {
                                "1": __('Type 1'),
                                "2": __('Type 2'),
                                "3": __('Type 3'),
                                "4": __('Type 4'),
                                "5": __('Type 5'),
                                "6": __('Type 6'),
                                "7": __('Type 7'),
                                "8": __('Type 8'),
                                "9": __('Type 9'),
                                "10": __('Type 10'),
                                "11": __('Type 11'),
                                "12": __('Type 12'),
                                "13": __('Type 13'),
                                "14": __('Type 14'),
                                "15": __('Type 15'),
                                "16": __('Type 16'),
                                "17": __('Type 17'),
                                "18": __('Type 18'),
                                "19": __('Type 19'),
                                "20": __('Type 20'),
                                "21": __('Type 21'),
                                "22": __('Type 22'),
                                "23": __('Type 23'),
                                "24": __('Type 24'),
                                "25": __('Type 25'),
                                "26": __('Type 26'),
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {
                            field: 'thumb',
                            title: __('Thumb'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.images,
                            events: Table.api.events.image,
                        },
                        {field: 'url', title: __('Url'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {
                            field: 'creator',
                            title: __('Creator'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                        },
                        {
                            field: 'created_at',
                            title: __('Created_at'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false
                        },
                        {
                            field: 'updater',
                            title: __('Updater'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                        },
                        {
                            field: 'updated_at',
                            title: __('Updated_at'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
